<template>
  <div class="box">
    <!-- 递归渲染 -->
    <reply
      v-if="parent.parent"
      :parent="parent.parent"
      @send="handlersend"
    ></reply>
    <div class="header">
      <div class="left">
        {{ parent.user.nickname
        }}<span>{{ parent.create_date | offsetTimeFormat }}</span>
      </div>
      <div class="right" @click="handlersend(parent)">回复</div>
    </div>
    <!-- 回复内容 -->
    <div class="con">{{ parent.content }}</div>
  </div>
</template>

<script>
// 过滤器
import { offsetTimeFormat } from "@/utils/filters";
export default {
  // 组件自己调用自己（递归）
  name: "reply",
  props: {
    parent: {},
  },
  filters: {
    offsetTimeFormat,
  },
  methods: {
    // 发出事件
    handlersend(parent) {
      console.log(parent);
      this.$emit("send", parent);
      // console.log(1);
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  font-size: 14px;
  margin: 10px;
  width: 100vw -20px;
  border: 1px solid #ccc;
  .header {
    display: flex;
    justify-content: space-between;
    padding: 5px;
    .right {
      font-size: 12px;
      color: #707070;
    }
    span {
      font-size: 12px;
      color: #707070;
      margin: 0 10px;
    }
  }
  .con {
    padding: 5px;
  }
}
</style>